<template>
  <div>
    <div class="linechart" :id="main_id"></div>
  </div>
</template>

<script>
import * as echarts from "echarts";

export default {
  name: "LineChart",
  data() {
    return {
      main_id: "mian" + Math.random(),
    };
  },
  mounted() {
    //页面加载完成之后要执行的操作放在这里
    this.initEchart();
  },
  methods: {
    initEchart() {
      var chartDom = document.getElementById(this.main_id);
      var myChart1 = echarts.init(chartDom);

      var option = {
        title: {
          text: "近一周交易数据",
          subtext: "近七天内的交易数量",
        },
        tooltip: {
          trigger: "axis",
        },
        xAxis: {
          type: "category",
          data: ["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"],
        },
        yAxis: {
          type: "value",
        },
        series: [
          {
            data: [820, 932, 901, 934, 1290, 1330, 1320],
            type: "line",
            smooth: true,
          },
        ],
      };
      //绘制图表
      myChart1.setOption(option);
    },
  },
};
</script>

<style scoped>
.linechart {
  width: 500px;
  height: 400px;
}
</style>